﻿using System;
using System.Collections.Generic;
using System.Text;
using SystemUI = System.Web.UI.WebControls;

namespace curbside.Web.UI.WebControls
{
    /// <summary>
    /// 文本域控件
    /// </summary>
    public class TextArea : SystemUI.TextBox
    {
        /// <summary>
        /// 更改TextBox的文本框行为模式
        /// </summary>
        public override SystemUI.TextBoxMode TextMode
        {
            get
            {
                return SystemUI.TextBoxMode.MultiLine;
            }
        }

        /// <summary>
        /// 重写Render方法
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            base.Render(writer);
            string jsEvent = "$(function(){var jtxt = $('#" + this.ClientID + "');";
            string jsCode = string.Empty;
            if (this.MaxLength > 0)
            {
                jsCode += "jtxt.keypress(function(e){if (this.value.length > " + MaxLength + ")return false;});";
            }

            if (!string.IsNullOrEmpty(jsCode))
            {
                jsEvent += jsCode + "});";
                helper.AddStartupScript(ClientID, jsEvent, this.Page);
            }
        }
    }
}
